﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t207Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t207_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t207Mgr mgr = new t207Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t207(e.Parameters[t207_Filter.ParamPrefix]));
            IList<t207> list = mgr.FindAllByPage_t207(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t207_Filter.ParamPrefix]);
            t207_MainStore.DataSource = list;
            t207_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t207Mgr mgr = new t207Mgr();
            RowSelectionModel sm = t207_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t207 _t207 = new t207();
                _t207.t207_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t207(_t207))
                {
                    log.Debug("t207中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t207_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t207Mgr mgr = new t207Mgr();
            t207 _t207 = new t207();
            if (Hid.Text.Length > 0)
                _t207 = mgr.FindById_t207(int.Parse(Hid.Text));
            
			_t207.t207_01 = Txtt207_01.Text.Trim();
			_t207.t207_02 = Txtt207_02.Text.Trim();
			_t207.t207_03 = Txtt207_03.Text.Trim();
			_t207.t207_04 = Txtt207_04.Text.Trim();
			_t207.t207_05 = Txtt207_05.Text.Trim();
			_t207.t207_06 = Txtt207_06.Text.Trim();
			_t207.t207_07 = Txtt207_07.Text.Trim();
			_t207.t207_08 = Txtt207_08.Text.Trim();
			_t207.t207_09 = Txtt207_09.Text.Trim();
			_t207.t207_10 = Txtt207_10.Text.Trim();
			_t207.t207_11 = Txtt207_11.Text.Trim();
			_t207.t207_12 = Txtt207_12.Text.Trim();
			_t207.t207_13 = Txtt207_13.Text.Trim();
			_t207.t207_14 = Txtt207_14.Text.Trim();
			_t207.t207_70 = Txtt207_70.Text.Trim();
			_t207.t207_15 = Txtt207_15.Text.Trim();
			_t207.t207_16 = Txtt207_16.Text.Trim();
			_t207.t207_17 = Txtt207_17.Text.Trim();
			_t207.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t207(_t207);
            else
                isok = mgr.Add_t207(_t207);
            if (isok)
            {
                t207_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t207中执行了保存（插入或修改），并成功");
                t207_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}